package br.ucb.cm.main.common;
import java.awt.Graphics;
import java.awt.Image;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class JImagePanel extends JPanel{  
	private static final long serialVersionUID = 1L;
	private Image image;
	
    public JImagePanel() {  
        super();  
    }  
    
    @Override  
    protected void paintComponent(Graphics g) {  
        super.paintComponent(g);  
        g.drawImage(image, 0, 0, null);  
    }  
    
    public void setImage(String resourcePath){
    	try {
			image = ImageIO.read(JImagePanel.class.getResource(resourcePath));
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
    
    public void setImage(String resourcePath, int width, int height){
    	try {
			image = ImageIO.read(JImagePanel.class.getResource(resourcePath)).getScaledInstance(width, height, Image.SCALE_SMOOTH);
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
    
    public void removeImage(){
    	image = null;
    }
}  